package com.csm.services.impl;

import java.util.ArrayList;
import java.util.List;

import com.commons.po.Customer;
import com.commons.po.StatusMsg;
import com.csm.dao.CustomerDao;
import com.csm.dao.StatusmsgDao;
import com.csm.dao.impl.CustomerDaoImpl;
import com.csm.dao.impl.StatusmsgDaoImpl;
import com.csm.services.CustomerService;

public class CustomerServiceImpl implements CustomerService{
	CustomerDao cd = new CustomerDaoImpl();
	StatusmsgDao sd = new StatusmsgDaoImpl();
	@Override
	public List<Customer> findAllCustomer() {
		List<Customer> list = new ArrayList<Customer>();
		list = cd.findAllCustomer();
		return list;
	}
	@Override
	public int addCustomer(Customer c) {
		int num = cd.saveUser(c);
		return num;
	}
	@Override
	public int updateCustomer(Customer user) {
		return cd.updateCustomer(user);
	}
	
	@Override
	public Customer findCustomerById(int CusId) {
		return cd.findCustomerById(CusId);
	}
	@Override
	public List<StatusMsg> findAll() {
		/*
		 * 1.查询StatusMsg所有数据
		 * 2.查询Customer所有数据
		 * 3.返回数据
		 */
		//1.查询StatusMsg所有数据
		List<StatusMsg> slist = sd.queryAll();
		//判断集合是否有值
		if(slist!=null && slist.size()>0){
			for(StatusMsg s : slist){
				int id = s.getId();
				s.setCustomer(cd.queryById(id));
			}
		}
		return slist;
	}
	@Override
	public boolean saveStatusMsg(StatusMsg user) {
		return sd.saveStatusMsg(user);
	}

}
